package test.examation;

import java.util.Scanner;

public class 京东 {
    public static void main(String[] args) {
//        m1();
        m2();
    }

    private static void m2() {//从n到m的数字，每个数字去掉其中任何一位后回文素数有几个

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int res=0;

        for(int i=n;i<=m;i++){
            String s = String.valueOf(i);
            int len=s.length();
            for(int j=len-1;j>=0;j--){
                String temp=s.substring(0,j)+s.substring(j+1,len);
                int a=Integer.parseInt(temp);
//                System.out.println(a);
                if(isPalindrome(a)){
                    if (isPrime(a)){
                        res++;
                        break;
                    }
                }
            }
        }
        System.out.println(res);
    }

    public static boolean isPrime(int x){

        int i = 2;
        for(;i<x;i++) {
            if (x % i == 0) {
                break;
            }
        }
        if(x == i){
            return true;
        }
        return false;
    }

    public static boolean isPalindrome(int x) {
        char[] chars=String.valueOf(x).toCharArray();
        int left=0;
        int right=chars.length-1;
        while (left<=right){
            if(chars[left++]!=chars[right--]){
                return false;
            }
        }
        return true;
    }

    private static void m1() {
        //计算1/5-1/10+1/15-...-1/(5*2n),四舍五入并且保留四位小数
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double f = 0d;
        double sum = 0d;
        for(int i = 1; i <= n; i++){
            f = 1d / (5 * (2 * i - 1)) - 1d / (5 * 2 * i);
            sum += f;
        }
        System.out.printf("%.4f", sum);
    }
}
